﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.SceneControl;

namespace Etapa1.SteeringExperiments
{
    public class Seek : Steering
    {
        public Seek(Vector3 target)
            : base(BehaviorType.seek)
        {
            this.target = target;
            isObj = false;
        }

        public Seek(IObject target) : base(BehaviorType.seek)
        {
            this.objTarget = target;
            isObj = true;
        }

        private Vector3 target;
        private IObject objTarget;
        bool isObj;

        public Vector3 Target
        {
            get { return target; }
            set { target = value; isObj = false; }
        }        

        public IObject ObjTarget
        {
            get { return objTarget; }
            set { objTarget = value; isObj = true; }
        }

        public override Microsoft.Xna.Framework.Vector3 CalculateSteering(SteeringEntityInfo entity)
        {            
            Vector3 DesiredVelocity = Vector3.Zero;
            if (isObj == true)
            {
                DesiredVelocity = Vector3.Normalize(objTarget.Position - entity.Obj.Position) * entity.MaxVelocity;
            }
            else
            {
                DesiredVelocity = Vector3.Normalize(target - entity.Obj.Position) * entity.MaxVelocity;
            }
            if (DesiredVelocity == Vector3.Zero)
                return Vector3.Zero;

            return (DesiredVelocity - entity.Obj.PhysicObject.Velocity);
        }
    }
}
